package com.jeeplus.modules.web.wx;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.web.entity.YJRoomUser;
import com.jeeplus.modules.web.mapper.YJRoomUserMapper;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author 十戒丶
 * @date 2021-02-06 22:07:07
 */
@Controller
@RequestMapping(value = "${adminPath}/wx/roomUser")
public class YjRoomUserBackController extends BaseController {
    @Autowired
    private YJRoomUserMapper yjRoomUserMapper;
    
    /**
     * 接口列表页面
     */
    @RequiresPermissions("wx:roomUser:list")
    @RequestMapping(value = {"list", ""})
    public String list(HttpServletRequest request, HttpServletResponse response, Model model) {
        model.addAttribute("yjRoomUser", new YJRoomUser());
        return "wx/roomUser/list";
    }
    
    @RequiresPermissions(value = {"wx:roomUser:view", "wx:roomUser:add", "wx:roomUser:edit"}, logical = Logical.OR)
    @RequestMapping(value = "form")
    public String form(YJRoomUser yjRoomUser, Model model) {
        model.addAttribute("yjRoomUser", yjRoomUser);
        if (StringUtils.isBlank(yjRoomUser.getId())) {//如果ID是空为添加
            model.addAttribute("isAdd", true);
        }
        return "wx/roomUser/form";
    }
    
    @ResponseBody
    @RequiresPermissions("wx:roomUser:list")
    @RequestMapping(value = "data")
    public Map<String, Object> data(YJRoomUser yjRoomUser, HttpServletRequest request, HttpServletResponse response, Model model) {
        final Page<YJRoomUser> page = new Page<>(request, response);
        yjRoomUser.setPage(page);
        page.setList(yjRoomUserMapper.findList(yjRoomUser));
        return getBootstrapData(page);
    }
}
